#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <set>

#define flr(x,l,r) for (int x = l; x <= r; ++ x)
#define frl(x,r,l) for (int x = r; x >= l; -- x)
#define fmp(x,t) for (int x = h[t]; ~x; x = ne[x])
#define LL long long 
#define mt memset
#define my memcpy 
#define szf sizeof
#define INF 0x3f3f3f3f
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define inll(x) scanf("%lld", &x)
#define outll(x) printf("%lld", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector
#define pb push_back
#define sz size
#define PII pair<int, int>
#define x first
#define y second
#define P_q priority_queue
#define ft front
#define pf push_front
#define popf pop_front
#define it insert
#define ct count

using namespace std;

const int N = 100010;

int n, m, cnt;
int row[N], col[N], s[N], c[N];

LL work(int n, int a[]) {
    flr (i, 1, n) s[i] = s[i - 1] + a[i];
    
    if (s[n] % n) return -1;
    
    c[1] = 0;
    int ave = s[n] / n;
    flr (i, 2, n) c[i] = s[i - 1] - (i - 1) * ave;
    
    sort(c + 1, c + n + 1);
    LL res = 0;
    flr (i, 1, n) res += abs(c[i] - c[(n + 1) / 2]);
    return res;
}

int main() {
    in(n), in(m), in(cnt);
    
    while (cnt -- ) {
        int x, y;
        in(x), in(y);
        row[x] ++ , col[y] ++ ;
    }
    
    LL r = work(n, row), c = work(m, col);
    
    if (r != -1 && c != -1) printf("both %lld\n", r + c);
    else if (r != -1) printf("row %lld\n", r);
    else if (c != -1) printf("column %lld\n", c);
    else puts("impossible");
    
    return 0;
}